/* **********************************************************************
版本: 2022.3.62f1
作者: wzz
日期: 2025-8-8
描述: 不要忘记添加描述哦~.~！
***********************************************************************/

using System;
using System.Buffers.Binary;
using System.IO;
using System.Net.Sockets;
using UnityEditor;

public class MyFast
{
    [MenuItem("wzz/快速添加引用 _F1", false, 1)]
    public static void FastAddScripts()
    {
        if (BitConverter.IsLittleEndian)
        {
            LogPro.DebugPro.Log("当前系统是小端（Little-Endian）");
        }
        else
        {
            LogPro.DebugPro.Log("当前系统是大端（Big-Endian）");
        }

        // 大端模式(Big Endian)
        //高位字节存储在内存低地址，低位字节存储在高地址。
        //*示例：整数 10 的4字节大端表示为 { 0, 0, 0, 10}
        //        *

        //小端模式(Little Endian)
        //低位字节存储在内存低地址，高位字节存储在高地址。
        //*示例：整数 10 的4字节小端表示为 { 10, 0, 0, 0}

        int num = 10;
        var numTrans = BinaryPrimitives.ReverseEndianness(num);
        var a1 = BitConverter.GetBytes(num);
        var a2 = BitConverter.GetBytes(numTrans);

        LogPro.DebugPro.Log($"小端：{num} 转成大端后：{numTrans}", LogPro.LogColor.Green);
        LogPro.DebugPro.Log($"小端数组", a1, "转成大端后数组：", a2, LogPro.LogColor.Green);

        byte[] arry1 = new byte[sizeof(int)];
        byte[] arry2 = new byte[] { 0, 0, 0, 10 };

        var mBinaryReader = new BinaryReader(new MemoryStream(arry2));

        var b1 = mBinaryReader.ReadInt32();
        var b2 = BinaryPrimitives.ReverseEndianness(b1);

        //BinaryPrimitives.WriteInt32BigEndian(arry1, num);
        //BinaryPrimitives.WriteInt32LittleEndian(arry2, num);
        LogPro.DebugPro.Log(b1, b2);

    }
}